<template>
  <div class="main">
    <header>
      <van-icon name="arrow-left" size=".5rem" />
      <van-search
        v-model="value"
        placeholder="全场50元起步"
        shape="round"
        style="width: 7rem"
      />
    </header>
    <van-sidebar @change="changeItem" v-model="activeKey">
      <van-sidebar-item
        :title="item.categoryName"
        v-for="item in category"
        :key="item.categoryId"
      >
      </van-sidebar-item>
    </van-sidebar>
    <div class="body">
      <CateItem :cateItems="cateItems"></CateItem>
    </div>
  </div>
</template>

<script>
import { categories } from "@/api/index";
import CateItem from "../../components/cateItem.vue";
export default {
  name: "Categary",
  created() {
    categories().then((data) => {
      this.category = data.data;
    });
  },
  data() {
    return {
      category: [],
      index: 0,
      activeKey: 0,
      value: "",
    };
  },
  methods: {
    changeItem(index) {
      this.index = index;
    },
  },
  components: { CateItem },
  computed: {
    cateItems() {
      return this.category[this.index].secondLevelCategoryVOS;
    },
  },
};
</script>
<style lang="less" scoped>
.main {
  display: flex;
  justify-content: space-between;
  .van-sidebar {
    flex: 1;
    margin-top: 1rem;
  }
  .body {
    flex: 2;
    overflow: scroll;
    margin-top: 1.5rem;
  }
}
header {
  position: fixed;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
</style>

